package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.service.UserPaidAlbumService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户已付款专辑")
@RestController
@RequestMapping("api/user/userPaidAlbum")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserPaidAlbumController {

    @Autowired
    private UserPaidAlbumService userPaidAlbumService;

    /**
     * 根据专辑id和用户id，查询该用户是否购买过该专辑
     *
     * @param albumId
     * @return
     */
    @GetMapping("/findUserPaidAlbum/{userId}/{albumId}")
    public Result<UserPaidAlbum> findUserPaidAlbum(@PathVariable("userId") Long userId,
                                                   @PathVariable("albumId") Long albumId) {
        UserPaidAlbum userPaidAlbum = userPaidAlbumService.lambdaQuery()
                .eq(UserPaidAlbum::getUserId, userId)
                .eq(UserPaidAlbum::getAlbumId, albumId)
                .one();
        return Result.ok(userPaidAlbum);
    }
}
